<template>
  <div class="edit-container">
    <el-form ref="form" :model="form" label-width="100px">
      <el-form-item label="商家" prop="businessId">
        <el-select v-model="form.businessId" filterable placeholder="请选择" style="width: 200px">
          <el-option
              v-for="item in list"
              :key="item.id"
              :label="item.businessName"
              :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="选择时间：">
        <el-date-picker
            v-model="value1"
            @change="handleChange"
            value-format="yyyy-MM-dd" format="yyyy-MM-dd"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width: 300px"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item class="el-icon-circle-plus-outline"
                    style="margin-top: 60px;width: 100%;display: flex;justify-content: center;">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handlerSubmit">导出</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {exportOrderRecords, getOrders} from "@/api/order";

export default {
  props: {
    id: {
      default: null
    }
  },
  data() {
    return {
      form: {
        id: null,
        businessId:'',
        beginTime: '',
        endTime: '',
      },
      value1:'',
      list: [],
      saveLoading: false,
      countdown: 0,
    }
  },
  mounted() {
    this.getGroupList()
  },
  methods: {
    getGroupList() {
      getOrders().then(res => {
        this.list = res;
      })
    },
    handleChange(value) {
      if (Array.isArray(value) && value.length === 2) {
        this.form.beginTime = value[0];
        this.form.endTime = value[1];
      }
    },
    handlerSubmit() {
      this.$refs.form.validate(valid => {
        if (!valid) return;
        this.saveLoading = true;
        exportOrderRecords(this.form).then(() => {
          this.close();
        }).finally(() => {
          this.saveLoading = false;
        });
      });
    },
    close() {
      this.$emit('hideExportOrder');
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep {
  .el-upload {
  }
}

.img {
  width: 80px;
  height: 80px;
  border-radius: 100px;
}
</style>
